<#include "${ftl_skin}/common/header.ftl">
<style type="text/css">

</style>
</head>
<body>

<div class="row ibox float-e-margins dialog-panel-body"  >
    <div class="ibox-content p-tb-none" >
        <form id="formId"  class="form form-horizontal" 
        	action="${path.servicePath }/user/useredit.do" method="post">

            <fieldset>

            <input type="hidden" name="itemid" id="itemid" class="form-control" value="${((userAccountVO.user_code)! == "")?string("", (userAccountVO.user_code)!) }" />

            <#--<input type="hidden" name="dept_id" id="dept_id" class="form-control" value="${(deptVO.tree_id)! }" />-->
            <input type="hidden" name="isGroupId" id="isGroupId" class="form-control" value="${(detectGroupVO.id)! }">
            <input type="hidden" name="isDeptId" id="isDeptId" class="form-control" value="${(deptVO.tree_id)! }">


            <div class="form-group">
                <label class="col-xs-2 control-label">部门名称</label>

                <div class="col-xs-10" id="dept">
                    <select class="form-control" name="dept_id" id="dept_id">
                    </select>
                </div>
            </div>
                <input type="hidden" id="group_id" name="group_id" value="0">
            <#--<div class="form-group" id="deptGroup" style="display: none">-->
                <#--<label class="col-xs-2 control-label">检测小组</label>-->

                <#--<div class="col-xs-10">-->
                    <#--<select required titl="检测小组" class="form-control" name="group_id"-->
                            <#--id="group_id" aria-invalid="false">-->
                    <#--</select>-->
                    <#--&lt;#&ndash;<select class="form-control" name="dept_id" id="dept_id">-->
                    <#--</select>&ndash;&gt;-->
                <#--</div>-->
            <#--</div>-->

            <div class="form-group">
                <label class="col-xs-2 control-label">用户编码<em class="start">*</em></label>

                <div class="col-xs-10">
                    <input id="user_code" name="user_code" class="form-control required" type="text" value="${(userAccountVO.user_code)!}" maxlength="50" ${((userAccountVO.user_code)! == "")?string("", "readonly") } />
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-2 control-label">用户密码<em class="start">*</em></label>

                <div class="col-xs-10">
                    <input id="user_password" 
                    	name="user_password" class="form-control ${((userAccountVO.user_code)! == "")?string("required", "") }" 
                    	type="password" value="" maxlength="50" placeholder="如不修改密码请不要输入内容" />
                    <br>ps:密码须包含数字，字母，特殊字符 "!","@","#","$","%","^","&","*"，且长度 >=8
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-2 control-label">用户姓名<em class="start">*</em></label>

                <div class="col-xs-10">
                    <input id="user_name" name="user_name" class="form-control required" type="text" value="${(userInfoVO.user_name)!}" maxlength="50" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-2 control-label">联系电话<em class="start">*</em></label>

                <div class="col-xs-10">
                    <input id="mobile_phone" name="mobile_phone" class="form-control required" type="text" value="${(userInfoVO.mobile_phone)!}" maxlength="50" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-2 control-label">电子邮箱<em class="start">*</em></label>

                <div class="col-xs-10">
                    <input id="e_mail_addr" name="e_mail_addr" class="form-control required" type="text" value="${(userInfoVO.e_mail_addr)!}" maxlength="50" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-xs-2 control-label">电子签名<em class="start">*</em></label>

                <div class="col-xs-10">
                    <input  id="signature_attach_id" name="signature_attach_id" value="${(userInfoVO.signature_attach_id)!''}" type="hidden">
                    <input  id="signature_attach_name" name="signature_attach_name" class="form-control col-sm-9"
                           placeholder="请上传附件" value="${(userInfoVO.signature_attach_name)!''}" type="text" readonly>
                    <div class="ibox-tools m-t-xs col-sm-3">
                        <a class="yxAjaxUpload-signature" href=""><i class="glyphicon glyphicon-open"></i></a>
                        <a class="" href="javascript:void(0);" onclick="attachDownload($('#signature_attach_id').val());"><i class="glyphicon glyphicon-save"></i></a>
                    </div>

                </div>
                <#--<div class="col-xs-1">
                    <a class="yxAjaxUpload-signature" href=""><i class="glyphicon glyphicon-open"></i></a>
                </div>
                <div class="col-xs-1">
                    <a onclick="attachDownload($('#signature_attach_id').val());"><i class="glyphicon glyphicon-save"></i></a>
                </div>-->
            </div>

            <div class="form-group">
                <label class="col-xs-2 control-label">所属角色</label>

                <div class="col-xs-10">
                    <#if list_role?? && list_role?size gt 0>
                        <#list list_role as item>

                            <div class="checkbox checkbox-success checkbox-inline">
                                <input type="checkbox" id="user_role_${item.role_code}"  name="user_role" value="${item.role_code}" />
                                <label for="user_role_${item.role_code}"> ${item.role_name} </label>
                            </div>

                        </#list>
                    </#if>
                </div>
            </div>
                <div class="form-group">
                    <label class="col-xs-2 control-label">所属岗位</label>

                    <div class="col-xs-10">
                    <#if list_position?? && list_position?size gt 0>
                        <#list list_position as item>

                            <div class="checkbox checkbox-success checkbox-inline">
                                <input type="checkbox" id="user_position_${item.id}"  name="user_position" value="${item.id}" />
                                <label for="user_position_${item.id}"> ${item.posi_name} </label>
                            </div>

                        </#list>
                    </#if>
                    </div>
                </div>

				<!-- 
				<#-- 
                <div class="form-group">
                    <label class="col-xs-2 control-label">用户标签</label>

                    <div class="col-xs-10">
                    <#if list_tags?? && list_tags?size gt 0>
                        <#list list_tags as item>

                            <div class="checkbox checkbox-success checkbox-inline">
                                <input type="checkbox" id="tags_${item.id}"  name="tags" value="${item.tag_title}" />
                                <label for="tags_${item.id}"> ${item.tag_title} </label>
                            </div>

                        </#list>
                    </#if>
                    </div>
                </div>
                -->
                -->
			<!--
			<#-- 
            <div class="form-group">
                <label class="col-xs-2 control-label">联系地址</label>

                <div class="col-xs-10">
                    <textarea id="contract_addr" name="contract_addr" class="form-control">${(userInfoVO.contract_addr)!}</textarea>
                </div>
            </div>
             -->
             -->
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-xs-4 col-xs-offset-2">
                    <button class="btn btn-primary" type="button" onClick="javascript:HFFormSubmit('#formId', submitCallback, null);return false;">保存内容</button>
                    <button class="btn btn-white" type="button" onClick="javascript:closeDialog('');return false;">取消</button>
                </div>
            </div>
            </fieldset>
        </form>
    </div>
</div>



<#include "${ftl_skin}/common/js.ftl">


<script type="text/javascript">
    $(function(){
    	//使弹窗可滚动，需在第一个div加dialog-panel-body
    	initDialogPanel();
        //初始化表单验证
        initHFForm('#formId');

        HFAjax("${path.servicePath}/dept/treelistauth.do", {
        }, function(resp){
            if(resp.state == 0){
                var $deptId = $("#dept_id");
                $deptId.empty();
                var data = resp.result;
                for(var i in data){
                    if (data[i].parent_tree_code != "-1" || data[i].parent_tree_code != -1){
                        if($("#isDeptId").val() != null && $("#isDeptId").val() != ""){
                            if($("#isDeptId").val() == data[i].dept_id){
                                $deptId.append("<option selected name='" + data[i].dept_name + "' value='" + data[i].dept_id + "'>" + data[i].dept_name + "</option>");
                            }else{
                                $deptId.append("<option name='" + data[i].dept_name + "' value='" + data[i].dept_id + "'>" + data[i].dept_name + "</option>");
                            }
                        }else{
                            $deptId.append("<option name='" + data[i].dept_name + "' value='" + data[i].dept_id + "'>" + data[i].dept_name + "</option>");
                        }
                    }
                }
            }
        });

        HFAjax("/HFDataStd/service/detectdept/search.do", {
            dept_id: $("#dept_id").val()
        }, function(resp){
            if(resp.state == 0){
                if (resp.result != null && resp.result != ""){
                    var id =  resp.result[0].id;
                    HFAjax("/HFDataStd/service/detectdept/searchgroup.do", {
                        dept_id: id
                    }, function(result){
                        if(result.state == 0){
                            var $groupId = $("#group_id")
                            $groupId.empty();
                            var data = result.result;
                            if(data != null && data != ""){
                                $("#deptGroup").show();
                                for (var i in data) {
                                    if($("#isGroupId").val() != null && $("#isGroupId").val() != ""){
                                        if($("#isGroupId").val() == data[i].id){
                                            $groupId.append("<option selected name='" + data[i].group_name + "' value='" + data[i].id + "'>" + data[i].group_name + "</option>");
                                        }else{
                                            $groupId.append("<option name='" + data[i].group_name + "' value='" + data[i].id + "'>" + data[i].group_name + "</option>");
                                        }
                                    }else{
                                        $groupId.append("<option name='" + data[i].group_name + "' value='" + data[i].id + "'>" + data[i].group_name + "</option>");
                                    }
                                }
                            }
                        }
                    });
                }else {
                    $("#deptGroup").hide();
                }
            }
        });

        $("#dept_id").change(function () {
            var dept_id = $(this).val();
            HFAjax("/HFDataStd/service/detectdept/search.do", {
                dept_id: dept_id
            }, function(resp){
                if(resp.state == 0){
                    if (resp.result != null && resp.result != ""){
                        var id =  resp.result[0].id;
                        HFAjax("/HFDataStd/service/detectdept/searchgroup.do", {
                            dept_id: id
                        }, function(result){
                            if(result.state == 0){
                                var $groupId = $("#group_id")
                                $groupId.empty();
                                var data = result.result;
                                if(data != null && data != ""){
                                    $("#deptGroup").show();
                                    for (var i in data) {
                                        $groupId.append("<option name='" + data[i].group_name + "' value='" + data[i].id + "'>" + data[i].group_name + "</option>");
                                    }
                                }
                            }
                        });
                    }else {
                        $("#deptGroup").hide();
                    }
                }
            });
        })



        <#if list_user_role?? && list_user_role?size gt 0>
            <#list list_user_role as item>
                $('#user_role_${item.role_code}').prop('checked', true);
            </#list>
        </#if>

        <#if list_user_position?? && list_user_position?size gt 0>
            <#list list_user_position as item>
                $('#user_position_${item.posi_id}').prop('checked', true);
            </#list>
        </#if>

        setCheckValue($('input[name=tags]'), '${userInfoVO.tags!}'.split(','));

        //电子签名附件上传
        $('.yxAjaxUpload-signature').yxAjaxUpload({
            success: uploadCallBack_signature,
            complete: function (res) {
                if (jQuery.isEmptyObject(res)) {
                    HFToastrError("上传附件失败，请联系运维工程师");
                    $('#submitBtn').removeAttr("disabled");
                }
            },
            dataType: 'text',
            url: "/hfattach/service/upload/uploadfile.do",
            submitBtn: "submitBtn"
        });
    });

    //上传电子签名回调
    function uploadCallBack_signature(result){
        result = $.parseJSON(result);
        if(result.ok == true){
            $("#signature_attach_id").val(result.fileContent.fileInfo.id);
            $("#signature_attach_name").val(result.fileContent.fileInfo.attach_name);
            HFToastr("上传附件成功");

        }else{
            HFToastrError("上传附件失败，请联系运维工程师");
        }
        $('#submitBtn').removeAttr("disabled");
    }
    //下载电子签名附件
    function attachDownload(attachId) {
        if(!isNull(attachId)){
            window.location.href = "/hfattach/service/download/Download.do?id=" + attachId;
        }else{
            HFAlert("未存在附件");
        }
    }


    function submitCallback(msg){
        // alert(JSON.stringify(msg));
        if(msg.state == 0){
            HFToastr("操作成功");
            closeDialog('reload');
        }else if(typeof msg.message != "undifined"){
        	HFToastrError(msg.message);
        }
    }


</script>

<#include "${ftl_skin}/common/footer.ftl">